<template>
    <Modal :value="value" @input="handleInput" width="746" :closable="false">
        <div slot="header">
            业务事项
            <Icon class="f-fr" type="ios-close" @click="closeModal"/>
        </div>
        <CheckboxGroup v-model="selectMatter">
            <Checkbox v-for="item in list" :key="item.label" :disabled="item.disabled || editORshow" :label="item.label"></Checkbox>
        </CheckboxGroup>
        <div slot="footer">
            <Button type="default" @click="closeModal">取消</Button>
            <Button type="primary" @click="saveBusMatter">确定</Button>
        </div>
    </Modal>
</template>

<script>
export default {
    name: 'BusMatterModal',
    props: {
        value: {
            default: false,
            type: Boolean
        },
        busMatter: {
            default: function () {
                return {
                    paperlessTax: '',
                    voluntaryTaxation: '',
                    sinceNewspaperPay: '',
                    chkSurety: '',
                    editORshow: false,
                    waterTransfer: ''
                }
            },
            type: Object
        }
    },
    data () {
        return {
            selectMatter: [],
            editORshow: '',
            list: [
                {
                    label: '税单无纸化',
                    disabled: this.editORshow
                },
                {
                    label: '自主报税',
                    disabled: this.editORshow
                },
                {
                    label: '水运中转',
                    disabled: this.editORshow
                },
                {
                    label: '自报自缴',
                    disabled: true
                },
                {
                    label: '担保验放',
                    disabled: true
                }
            ]
        }
    },

    created () {
        this.init(this.busMatter)
    },

    methods: {
        init (obj) {
            this.editORshow = obj.editORshow
            this.$nextTick(() => {
                this.selectMatter = []
                if (obj.paperlessTax == 1) {
                    this.selectMatter.push('税单无纸化')
                }
                if (obj.voluntaryTaxation == 1) {
                    this.selectMatter.push('自主报税')
                }
                if (obj.sinceNewspaperPay == 1) {
                    this.selectMatter.push('自报自缴')
                }
                if (obj.chkSurety == 1) {
                    this.selectMatter.push('担保验放')
                }
                if (obj.waterTransfer == 1) {
                    this.selectMatter.push('水运中转')
                }
            })
        },

        saveBusMatter () {
            let obj = {
                paperlessTax: 0,
                voluntaryTaxation: 0,
                sinceNewspaperPay: 0,
                chkSurety: 0,
                waterTransfer: 0
            }
            for (let i in this.selectMatter) {
                if (this.selectMatter[i] === '税单无纸化') {
                    obj.paperlessTax = 1
                }
                if (this.selectMatter[i] === '自主报税') {
                    obj.voluntaryTaxation = 1
                }
                if (this.selectMatter[i] === '自报自缴') {
                    obj.sinceNewspaperPay = 1
                }
                if (this.selectMatter[i] === '担保验放') {
                    obj.chkSurety = 1
                }
                if (this.selectMatter[i] === '水运中转') {
                    obj.waterTransfer = 1
                }
            }
            this.$emit('saveBusMatter', obj)
            this.closeModal()
        },
        handleInput (v) {
            this.$emit('input', v)
        },
        closeModal () {
            this.handleInput(false)
        }
    }
}
</script>

<style scoped>

</style>
